package com.slkj.shilixiaoyuanapp.view.dialog;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.slkj.shilixiaoyuanapp.R;

public class LoadingDialog extends AlertDialog {

    ImageView iv_loadimg;
    TextView tv_loadtext;
    int layoutid;
    String msg;
    int resid;

    public LoadingDialog(@NonNull Context context) {
        super(context, R.style.normal_dialog);
    }

    public LoadingDialog(@NonNull Context context,int layoutid) {
        super(context, R.style.normal_dialog);
        this.layoutid=layoutid;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);//状态栏透明
        getWindow().setBackgroundDrawableResource(R.drawable.selector_choose_dialog_corner);
        getWindow().setLayout(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
        setContentView(R.layout.dialog_loadingsuccess);
        initWidget();
        init();
    }

    private void init() {
        tv_loadtext.setText(msg);
        Glide.with(getContext()).load(resid).asGif() .diskCacheStrategy(DiskCacheStrategy.SOURCE).into(iv_loadimg);
    }


    private void initWidget() {
        iv_loadimg=findViewById(R.id.iv_loadimg);
        tv_loadtext=findViewById(R.id.tv_loadtext);
        //dialog基本设置
        setCanceledOnTouchOutside(false);
        setCancelable(false);
    }

    public  void setMsg(String msg){
        this.msg=msg;
    }

    public void setImg(int resid){
        this.resid=resid;
    }
}
